﻿<Window x:Class="ResourceBlender.Express.WinEditResx"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:loc="clr-namespace:ResourceBlender.Express"
    xmlns:validators="clr-namespace:ResourceBlender.Express.Validators"
    xmlns:props="clr-namespace:ResourceBlender.Express.Properties"
    Title="Resx Resource Editor" WindowStartupLocation="CenterOwner"
    Height="500" Width="600" MinHeight="450" MinWidth="350" Loaded="Window_Loaded"
    Style="{StaticResource {x:Type Window}}" Icon="/ResourceBlenderExpress;component/Resources/images/resourceblender.ico" ResizeMode="CanResize">
    <Window.CommandBindings>
        <CommandBinding Command="loc:ResourceBlenderCommands.AutoTranslate" Executed="AutoTranslate" />
        <CommandBinding Command="loc:ResourceBlenderCommands.AutoSave" Executed="ToggleAutoSave" />
        <CommandBinding Command="loc:ResourceBlenderCommands.OpenFullEditor" Executed="ShowFullEditor" />
        <!--CommandBinding Command="loc:ResourceBlenderCommands.FilterGrid" Executed="FilterGrid" /-->
        <CommandBinding Command="NavigationCommands.Favorites" Executed="ShowShortcuts" />
        <CommandBinding Command="ApplicationCommands.Close" Executed="CloseWindow" />
        <CommandBinding Command="ApplicationCommands.Delete" Executed="DeleteResource" CanExecute="CanExecuteDeleteResource" />     
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.New" Executed="AddResource" CanExecute="CanAlwaysExecute" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="Save" CanExecute="CanExecuteSave" />
    </Window.CommandBindings>
    <Window.Resources>
        <BitmapImage x:Key="database_16" UriSource="pack://application:,,,/Resources/images/database_16.png" />
        <Image x:Key="save_16" Source="pack://application:,,,/Resources/images/save_16.png" />
        <Image x:Key="question_16" Source="pack://application:,,,/Resources/images/question_16.png" />
        <Image x:Key="AddResource_16" Source="pack://application:,,,/Resources/images/doc_add_16.png" />
        <Image x:Key="DeleteResource_16" Source="pack://application:,,,/Resources/images/doc_delete_16.png" />
        <props:Settings x:Key="settings" />
    </Window.Resources>
    <DockPanel LastChildFill="True" DataContext="{StaticResource settings}">
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Header="_Save" Command="ApplicationCommands.Save" Icon="{StaticResource save_16}" />
                <MenuItem Header="_AutoSave" x:Name="itmAutoSave" Command="loc:ResourceBlenderCommands.AutoSave" IsCheckable="True" IsChecked="{Binding Path=Default.AutoSave,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  />
                <MenuItem Header="E_xit" Command="ApplicationCommands.Close" />
            </MenuItem>
            <MenuItem Header="Automatic _Translation">
                <MenuItem Header="_Source Language" x:Name="mnuSrcLanguage" />
                <MenuItem Header="_Destination Language" x:Name="mnuDestLanguage" />
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Header="_Editing Resx Files" Command="ApplicationCommands.Help" Icon="{StaticResource question_16}" />
                <MenuItem Header="_Shortcut Keys" Command="NavigationCommands.Favorites" />
            </MenuItem>
        </Menu>
        <DockPanel DockPanel.Dock="Top" LastChildFill="True" HorizontalAlignment="Stretch" Width="Auto">
            <ToolBar DockPanel.Dock="Right" BorderThickness="0,0,1,1">
                <loc:ImageButton Command="NavigationCommands.Favorites" Text="Shortcut Keys" Image="Resources/images/help_keyboard_24.png" ShowText="False" ToolTip="Shortcut Keys" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton Command="ApplicationCommands.Help" Text="Show Help" Image="Resources/images/question_24.png" ShowText="False" ToolTip="Editing Resx Files" Style="{StaticResource ToolBarButton}" />
            </ToolBar>
            <ToolBar DockPanel.Dock="Left" BorderThickness="1,0,0,1">
                <loc:ImageButton x:Name="btnAdd" Command="ApplicationCommands.New" Text="Add" Image="pack://application:,,,/Resources/images/add_24.png" ToolTip="Add Resource" Style="{StaticResource ToolBarButton}" />
                <loc:ImageButton x:Name="btnDelete" Command="ApplicationCommands.Delete" Text="Delete" Image="pack://application:,,,/Resources/images/delete_24.png" ToolTip="Delete Resource" Style="{StaticResource ToolBarButton}" />
                <Separator />
                <loc:ImageButton x:Name="btnSave" Command="ApplicationCommands.Save" Text="Save" Image="pack://application:,,,/Resources/images/save_24.png" ToolTip="Save File" Style="{StaticResource ToolBarButton}" />
                <!--ToggleButton x:Name="btnFilters" ToolTip="Toggle Filters Panel">
                <ToggleButton.IsChecked>
                    <Binding Path="Default.FiltersVisible" Mode="TwoWay" />
                </ToggleButton.IsChecked>
                <StackPanel>
                    <Image Source="pack://application:,,,/Resources/images/filter_24.png" />
                    <TextBlock>Filters</TextBlock>
                </StackPanel>
            </ToggleButton-->
            </ToolBar>
        </DockPanel>
        <!--Expander DockPanel.Dock="Top" Header="Filters" Margin="6,6,6,0" Style="{StaticResource ButtonlessExpander}" IsExpanded="{Binding ElementName=btnFilters,Path=IsChecked}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="3*" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Label Grid.Row="0" Grid.Column="0">Name</Label>
                <ComboBox Grid.Row="0" Grid.Column="1" x:Name="cboNameFilter" SelectionChanged="cboFilter_SelectionChanged" />
                <TextBox Grid.Row="0" Grid.Column="2" x:Name="txtNameFilter" TextChanged="txtFilter_TextChanged" />

                <Label Grid.Row="1" Grid.Column="0">Translation</Label>
                <ComboBox Grid.Row="1" Grid.Column="1" x:Name="cboTranslationFilter" SelectionChanged="cboFilter_SelectionChanged" />
                <TextBox Grid.Row="1" Grid.Column="2" x:Name="txtTranslationFilter" TextChanged="txtFilter_TextChanged" />

                <Label Grid.Row="2" Grid.Column="0">Comment</Label>
                <ComboBox Grid.Row="2" Grid.Column="1" x:Name="cboCommentFilter" SelectionChanged="cboFilter_SelectionChanged" />
                <TextBox Grid.Row="2" Grid.Column="2" x:Name="txtCommentFilter" TextChanged="txtFilter_TextChanged" />

                <CheckBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" x:Name="chkLiveFilter" Content="Filter while typing" IsChecked="{Binding Default.LiveFilter,Mode=TwoWay}" />

                <StackPanel Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal">
                    <loc:ImageButton x:Uid="loc:ImageButton_5" Margin="0,2,2,2" Image="pack://application:,,,/Resources/images/filter_16.png" ImageLocation="Left" Text="Apply Filters" MinWidth="70" Command="loc:ResourceBlenderCommands.FilterGrid" IsDefault="True">
                        <Button.Style>
                            <Style TargetType="{x:Type loc:ImageButton}" BasedOn="{StaticResource {x:Type loc:ImageButton}}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=chkLiveFilter, Path=IsChecked}" Value="True">
                                        <Setter Property="Button.IsEnabled" Value="false"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>
                    </loc:ImageButton>
                    <loc:ImageButton x:Uid="loc:ImageButton_6" Image="pack://application:,,,/Resources/images/unfilter_16.png" ImageLocation="Left" Text="Clear Filters" MinWidth="70" Command="loc:ResourceBlenderCommands.FilterGrid" CommandParameter="clear" />
                </StackPanel>
            </Grid>
        </Expander-->
        <StatusBar DockPanel.Dock="Bottom" Height="24">
            <DockPanel LastChildFill="True">
                <Image DockPanel.Dock="Left" Source="{StaticResource database_16}" />
                <TextBlock x:Name="lblDb" DockPanel.Dock="Left" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" />
                <TextBlock x:Name="lblStatus" DockPanel.Dock="Right" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap">Loading Summary</TextBlock>
                <ProgressBar x:Name="prgStatus" DockPanel.Dock="Left" IsIndeterminate="True" MinWidth="40" Visibility="Hidden" />
            </DockPanel>
        </StatusBar>
        
        <!-- The default column templates are crap, mine work better ;) -->
        <dg:DataGrid x:Name="dgResources" DockPanel.Dock="Bottom" Margin="6" AutoGenerateColumns="False" SelectionMode="Single" SelectionUnit="Cell" 
                     EnableRowVirtualization="True" EnableColumnVirtualization="True" HeadersVisibility="Column" RowDetailsVisibilityMode="Collapsed" SelectedValuePath="Name" 
                     CanUserAddRows="True" CanUserDeleteRows="True" CanUserSortColumns="True" CanUserReorderColumns="False" RowEditEnding="dgResources_RowEditEnding">
            <!--  InitializingNewItem="dgResources_InitNewItem" CellEditEnding="dgResources_CellEditEnding"  -->
            <dg:DataGrid.Columns>
                <dg:DataGridTemplateColumn x:Name="colName" Header="Name" SortMemberPath="Name">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Width="150" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0"  />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox x:Name="txtName" Text="{Binding Name,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Initialized="txt_Initialized" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                </dg:DataGridTemplateColumn>
                
                <dg:DataGridTemplateColumn x:Name="colTranslation" Header="Translation" SortMemberPath="Translation">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Translation}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Width="200" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel HorizontalAlignment="Left">
                                <TextBox x:Name="txtTranslation" Text="{Binding Translation,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" AcceptsReturn="True" AcceptsTab="False" TextWrapping="Wrap" Initialized="txt_Initialized" Width="200" />
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                <loc:ImageButton x:Name="btnFullEditorTranslation" Image="pack://application:,,,/Resources/images/resource_expand_16.png" ShowText="False" 
                                    ToolTip="Open the full editor for this translation" Margin="1"
                                    Command="loc:ResourceBlenderCommands.OpenFullEditor" CommandTarget="{Binding ElementName=txtTranslation}" />
                                    <loc:ImageButton x:Name="btnAutoTranslate" Image="Resources/images/autotranslate_16.png" ShowText="False" Margin="1"
                                        Command="loc:ResourceBlenderCommands.AutoTranslate" CommandTarget="{Binding ElementName=txtTranslation}" ToolTip="Automatically translate this text" />
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                    <!--dg:DataGridTemplateColumn.CellStyle>
                        <Style TargetType="{x:Type dg:DataGridCell}" BasedOn="{x:Type dg:DataGridCell}">
                            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
                        </Style>
                    </dg:DataGridTemplateColumn.CellStyle-->
                </dg:DataGridTemplateColumn>
                
                <dg:DataGridTemplateColumn x:Name="colComment" Header="Comment" SortMemberPath="Comment">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Comment}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" Width="150" VerticalAlignment="Top" HorizontalAlignment="Left" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Comment,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Initialized="txt_Initialized" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                </dg:DataGridTemplateColumn>
                
                <dg:DataGridTemplateColumn x:Name="colType" Header="Type" SortMemberPath="Type">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Type}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Width="100" VerticalAlignment="Top" HorizontalAlignment="Left" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Type,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Initialized="txt_Initialized" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                </dg:DataGridTemplateColumn>
                
                <dg:DataGridTemplateColumn x:Name="colMimeType" Header="Mime Type" SortMemberPath="MimeType">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MimeType}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Width="100" VerticalAlignment="Top" HorizontalAlignment="Left" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                    <dg:DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding MimeType,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Initialized="txt_Initialized" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellEditingTemplate>
                </dg:DataGridTemplateColumn>
            </dg:DataGrid.Columns>
            <dg:DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="_Delete"  Icon="{StaticResource DeleteResource_16}" Command="ApplicationCommands.Delete" />
                </ContextMenu>
            </dg:DataGrid.ContextMenu>
            <dg:DataGrid.RowValidationRules>
                
            </dg:DataGrid.RowValidationRules>
            <dg:DataGrid.RowValidationErrorTemplate>
                <ControlTemplate>
                    <Grid>
                        <Grid.ToolTip>
                            <ToolTip Content="Name must be unique" />
                        </Grid.ToolTip>
                        <Image Source="pack://application:,,,/Resources/images/error_16.png" VerticalAlignment="Center" HorizontalAlignment="Left" />
                    </Grid>
                </ControlTemplate>
            </dg:DataGrid.RowValidationErrorTemplate>
        </dg:DataGrid>
    </DockPanel>
</Window>
